package com.freesky.provider.order.controller;

import com.freesky.common.pojo.Result;
import com.freesky.common.utils.ResultUtil;
import com.freesky.common.dao.entity.Thanks;
import com.freesky.provider.order.service.IOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author Freesky
 */
@RestController
@RequestMapping("/pay")
public class PayController {
    @Autowired
    private IOrderService orderService;

    @GetMapping(value = "/pass")
    public Result<Object> payPass(
            @RequestParam(value = "tokenName") String tokenName,
            @RequestParam(value = "token") String token,
            @RequestParam(value = "id") String id) {

        int result = orderService.passPay(tokenName, token, id);
        if (result == -1) {
            return new ResultUtil<Object>().setErrorMsg("无效的Token或链接");
        }
        if (result == 0) {
            return new ResultUtil<Object>().setErrorMsg("数据处理出错");
        }
        return new ResultUtil<Object>().setData("处理成功");
    }

    @GetMapping(value = "/back")
    public Result<Object> backPay(
            @RequestParam(value = "tokenName") String tokenName,
            @RequestParam(value = "token") String token,
            @RequestParam(value = "id") String id) {

        int result = orderService.backPay(tokenName, token, id);
        if (result == -1) {
            return new ResultUtil<Object>().setErrorMsg("无效的Token或链接");
        }
        if (result == 0) {
            return new ResultUtil<Object>().setErrorMsg("数据处理出错");
        }
        return new ResultUtil<Object>().setData("处理成功");
    }

    @GetMapping(value = "/passNotShow")
    public Result<Object> payNotShow(
            @RequestParam(value = "tokenName") String tokenName,
            @RequestParam(value = "token") String token,
            @RequestParam(value = "id") String id) {

        int result = orderService.notShowPay(tokenName, token, id);
        if (result == -1) {
            return new ResultUtil<Object>().setErrorMsg("无效的Token或链接");
        }
        if (result == 0) {
            return new ResultUtil<Object>().setErrorMsg("数据处理出错");
        }
        return new ResultUtil<Object>().setData("处理成功");
    }

    @GetMapping(value = "/edit")
    public Result<Object> payEdit(
            @RequestParam(value = "tokenName") String tokenName,
            @RequestParam(value = "token") String token,
            @ModelAttribute Thanks thanks) {

        int result = orderService.editPay(tokenName, token, thanks);
        if (result == -1) {
            return new ResultUtil<Object>().setErrorMsg("无效的Token或链接");
        }
        if (result == 0) {
            return new ResultUtil<Object>().setErrorMsg("数据处理出错");
        }
        return new ResultUtil<Object>().setData("处理成功");
    }

    @GetMapping(value = "/delNotNotify")
    public Result<Object> delNotNotify(
            @RequestParam(value = "tokenName") String tokenName,
            @RequestParam(value = "token") String token,
            @RequestParam(value = "id") String id) {

        int result = orderService.payDelNotNotify(tokenName, token, id);
        if (result == -1) {
            return new ResultUtil<Object>().setErrorMsg("无效的Token或链接");
        }
        if (result == 0) {
            return new ResultUtil<Object>().setErrorMsg("数据处理出错");
        }
        return new ResultUtil<Object>().setData("处理成功");
    }

    @GetMapping(value = "/del")
    public Result<Object> payDel(
            @RequestParam(value = "tokenName") String tokenName,
            @RequestParam(value = "token") String token,
            @RequestParam(value = "id") String id) {

        int result = orderService.payDel(tokenName, token, id);
        if (result == -1) {
            return new ResultUtil<Object>().setErrorMsg("无效的Token或链接");
        }
        if (result == 0) {
            return new ResultUtil<Object>().setErrorMsg("数据处理出错");
        }
        return new ResultUtil<Object>().setData("处理成功");
    }
}
